package com.isoft.controll;

import com.isoft.menu.Menu;
import com.isoft.pojo.Goods;
import com.isoft.service.GoodsService;

import java.util.Scanner;

public class GoodsController {
    Scanner scanner;
    //Alt+insert (Alt+fn+insert)
    GoodsService goodsService;

    public GoodsController() {
        scanner = new Scanner(System.in);
        goodsService = new GoodsService();
    }

    public void startSystem() {
        try {
            Goods goods;
            String goodsId = "";//运行时输入
            do {
                Menu.sysMenu();
                String userSelect = scanner.next();
                switch (userSelect) {
                    case "1":
                        goods = new Goods();
                        System.out.print("请输入商品 ID:");
                        String id = scanner.next();  System.out.print("请输入商品名称:");
                        String goodsName = scanner.next();
                        System.out.print("请输入商品类型:");
                        String goodsType = scanner.next();
                        System.out.print("请输入商品库存:");
                        int inventory = scanner.nextInt();
                        System.out.print("请输入商品单价:");
                        double price = scanner.nextDouble();
                        goods.setGoodsId(id);
                        goods.setGoodsName(goodsName);
                        goods.setGoodsType(goodsType);
                        goods.setInventory(inventory);
                        goods.setPrice(price);
                        goodsService.addGoods(goods);
                        break;
                    case "2":
                        System.out.print("请输入要删除的商品 ID:");
                        goodsId = scanner.next();
                        goodsService.deleteGoods(goodsId);
                        break;
                    case "3":
                        goods = new Goods();
                        //给 goods 赋值
                        goodsService.updateGoods(goods);
                        break;
                    case "4":
                        System.out.print("请输入要查询的商品 ID:");
                        goodsId = scanner.next();
                        goodsService.findGoodsByID(goodsId);
                        break;
                    case "5":
                        exit();
                        break;
                }
                System.out.println("按任意键继续...");  System.in.read();
            } while (true);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("系统出错了，请重试");
        }//Ctrl+Alt+L 格式化代码

    }

    public void exit() {

    }
}